#ifndef _FIGURE_HPP_
#define _FIGURE_HPP_

#include "include.hpp"
#include "itemdata.hpp"

class figure:public item_data {
	
public:
	string input_file;
	string pin;
	double scalex,scaley;

	figure(string newname, xlider_presentation* master):
	item_data(newname,0,master){
		type="figure";
	}
	
	// accepts absolute pixel coordinates
	virtual void sync_coord(){
		if(x>1.0)x/=slide_width;
		if(y>1.0)y/=slide_height;
		if(width>1.0)width/=slide_width;
		if(height>1.0)height/=slide_height;
	}

	virtual void read_theme(xml_config_reader& xc, param_handler& p, string ty){
		item_data::read_theme(xc,p,ty);
		
		// addition to item_data: scale, file, pin
		// FIXME! figure disobey this!
		
		read_theme_entry(xc, "pin", pin, "center");
		width=p.exist("width")?p.double_value("width"):0.0;
		height=p.exist("height")?p.double_value("height"):0.0;
		scalex=scaley=0.0;
		if(p.exist("scale"))scalex=scaley=p.double_value("scale");
		if(p.exist("scalex"))scalex=p.double_value("scalex");
		if(p.exist("scaley"))scaley=p.double_value("scaley");
		input_file=p.string_value("file");
		pin=p.string_value("pin");
		if(pin=="")pin="center";
		sync_coord();
	}

	virtual void set_textwidth(double wdt){};

	virtual void pinning(){
		if(pin=="center"){
			x-=width/2.0;
			y-=height/2.0;
		} else if(pin!="topleft") {
			THROW("only topleft and center pinning are supported");
		}
	}
	
};

#endif
